package idea.think;

import idea.think.db.IT_sql;
import android.app.Activity;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class IT_menu extends Activity {

	private ImageView mBtnAdd, mBtnAllIdea;
	private IT_sql sql;
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		
		sql = new IT_sql(this);
		SQLiteDatabase db = sql.getWritableDatabase();
		Cursor cursor = db.query(IT_sql.CATEGORY_TBL, null, null, null, null, null, null);
		
		//카테고리 DATA가 없을경우, 추가한다.
		if(cursor.getCount() == 0){
			ContentValues values = new ContentValues();			
			values.put("catename", "환경");			
			db.insertOrThrow(IT_sql.CATEGORY_TBL, null, values);
			values.put("catename", "경쟁");
			db.insertOrThrow(IT_sql.CATEGORY_TBL, null, values);
			values.put("catename", "가치");
			db.insertOrThrow(IT_sql.CATEGORY_TBL, null, values);
			values.put("catename", "전체");			
			db.insertOrThrow(IT_sql.CATEGORY_TBL, null, values);
		}
		
		Cursor cursor2 = db.query(IT_sql.IDEA_TBL, null, null, null, null, null, null);
		
		//아이디어 DATA가 없을경우, 추가한다.
		if(cursor2.getCount() == 0){
			ContentValues values = new ContentValues();
			
			values.put("catename", "환경");
			values.put("idea1", "화면크기");
			values.put("idea2", "LCD");
			values.put("idea3", "OLED");		
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "환경");
			values.put("idea1", "3G 무선");
			values.put("idea2", "4G 무선");
			values.put("idea3", "배터리용량");		
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "환경");
			values.put("idea1", "인텔칩");
			values.put("idea2", "키패드");
			values.put("idea3", "모블린");		
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "경쟁");
			values.put("idea1", "미니탭");
			values.put("idea2", "사스(SAS)");
			values.put("idea3", "SPSS");
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "가치");
			values.put("idea1", "만족");
			values.put("idea2", "흥미");
			values.put("idea3", "재미");
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "가치");
			values.put("idea1", "시간때우기");
			values.put("idea2", "밝은빛");
			values.put("idea3", "적절한자극");
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "가치");
			values.put("idea1", "택시호출");
			values.put("idea2", "기차표 예약");
			values.put("idea3", "관광상품구매");
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
			
			values.put("catename", "가치");
			values.put("idea1", "사진찍기");
			values.put("idea2", "게임");
			values.put("idea3", "음악");
			db.insertOrThrow(IT_sql.IDEA_TBL, null, values);
		}
		
		mBtnAdd = (ImageView) findViewById(R.id.ideaAdd);
		mBtnAllIdea = (ImageView) findViewById(R.id.allIdea);
				
		//idea 추가
		mBtnAdd.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {				
				Intent intent = new Intent(IT_menu.this, IdeaAdd.class);
				startActivity(intent);
			}
		});
		
		//전체 idea
		mBtnAllIdea.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {				
				Intent intent = new Intent(IT_menu.this, IdeaAll.class);
				startActivity(intent);
			}
		});
	}
	
	@Override
	public void onBackPressed() {
		new CustomAlertDialog(this)
		.setTitle("Idea_Thinking")
		.setMessage("종료 하시겠습니까")
		.setPositiveButton("예", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				finish();
			}
		})
		
		.setNegativeButton("아니오", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		})
		
		.show();
	}
}